package arithmetic.thread;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author jiangfeng 2019/7/16 00:26
 */
public class CallableFutureTaskDome {


    @Test
    public void test(){

        FutureTask futureTask = new FutureTask(() -> {
            return "adsf";
        });
        new Thread(futureTask).start();
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test2() throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask =new FutureTask(()->{
            System.out.println(Thread.currentThread().getName()+" featureTask启动了");
            return 1024;});
        new Thread(futureTask, "AA"). start();
        new Thread(futureTask, "BB"). start();
        System.out.println(futureTask.get());
    }

}
